<?php
session_start();

//Debug
error_reporting(E_ALL);
ini_set('display_errors', '1');



//carico il file che contiene tutti gli include
require_once('./configs/constants.php');
require_once('./configs/fnc_navigation.php');

//file di configurazione database
require_once('./configs/DataSource.class.php');

$connection = new Datasource("localhost", "phptemplateadmin", "root", "juventina");

$smarty = new Smarty;

if(!empty($_GET)){
	$pg = $_GET['pg'];
	$template = $pg.".tpl";
}
else if( empty($_GET) || (!$pg || !file_exists("pages/$pg.php"))) {
	$pg = 'login';
	$template = $pg.".tpl";
}

$smarty->caching = false;
$smarty->compile_check = true;
$smarty->debugging = false;

// carico la pagina in base
// alla pagina selezionata

$page404 = "404";
if(!file_exists("pages/$pg.php") || !file_exists("templates/$pg.tpl")){
	$pg = $page404;
}


include "pages/$pg.php";

/*
 * 	Assegno il template in base alla pagina selezionata 
*/
$template = $pg.".tpl";

$smarty->Assign("pg", $pg);


$menu = getNavigationBack();

$smarty->Assign("menu", $menu);

// mostro il template
if(isset($_GET['ajax']) && $_GET['ajax'] == "on")
{
}
else{
	$smarty->display($template);
}


?>
